home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Power 1998 April
/
MACPOWER-1998-04.ISO.7z
/
MACPOWER-1998-04.ISO
/
Shareware Paradise
/
Tabler.091.sit
/
Tabler 0.9.1
/
source code
/
Tabler.App.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-11-02
|
4KB
|
166 lines
/*
*--------------------------------------------------------------
* Tabler.App.c
*--------------------------------------------------------------
* Application verion of Tabler
*--------------------------------------------------------------
*/
/* System Include Headers */
#include <Types.h>
#include <Memory.h>
#include <Events.h>
#include <AppleEvents.h>
#include <Scrap.h>
#include <Resources.h>
#include <Files.h>
#include <Sound.h>
#include <Errors.h>
/* Project Include Header */
#include "Tabler.h"
/* Static functions only used in this source */
static void InitMacintoshToolbox(void);
Boolean gDone = false;
/* Implementation */
/*
*--------------------------------------------------------------
* main
*--------------------------------------------------------------
* main is main, cannot be whatever else.
*--------------------------------------------------------------
*/
void main(void)
{
OSErr result;
InitMacintoshToolbox();
PlayAClick();
if (SetUpMyAppleEvent()) {
do {
EventRecord anEvent;
if (WaitNextEvent(highLevelEventMask, &anEvent, -1, nil)) {
if (anEvent.what == kHighLevelEvent) {
result = AEProcessAppleEvent(&anEvent);
}
}
} while (gDone == false);
RemoveMyAppleEvent();
} else {
result = ConvertScrap();
}
if (result != noErr) {
SysBeep(20);
}
}
/*
*--------------------------------------------------------------
* InitMacintoshToolbox
*--------------------------------------------------------------
* standard intialization
*--------------------------------------------------------------
*/
static void InitMacintoshToolbox(void)
{
MaxApplZone();
MoreMasters();
InitGraf(&qd.thePort);
InitFonts();
InitWindows();
InitMenus();
TEInit();
InitDialogs(0);
InitCursor();
FlushEvents(everyEvent, 0);
}
/*
*--------------------------------------------------------------
* OpenSourceDoc
*--------------------------------------------------------------
* open a text file and copy its contents to the scrap
*--------------------------------------------------------------
*/
OSErr OpenSourceDoc(const FSSpec *theSpec)
{
FInfo aDocInfo;
Handle textHandle = nil;
long textSize = 0;
short fRefNum;
OSErr result;
result = FSpGetFInfo(theSpec, &aDocInfo);
if (result == noErr) {
if (aDocInfo.fdType == 'TEXT') {
result = FSpOpenDF(theSpec, fsRdPerm, &fRefNum);
if (result == noErr) {
result = GetEOF(fRefNum, &textSize);
if (result == noErr) {
textHandle = NewHandle(textSize);
if (textHandle != nil) {
HLock(textHandle);
result = FSRead(fRefNum, &textSize, *textHandle);
if (result == noErr) {
ZeroScrap();
result = (OSErr)PutScrap(textSize, 'TEXT', *textHandle);
DisposeHandle(textHandle);
textHandle = nil;
if (result == noErr) {
result = ConvertScrap();
}
}
if (textHandle != nil) {
DisposeHandle(textHandle);
}
} else {
result = MemError();
}
}
FSClose(fRefNum);
}
} else if (aDocInfo.fdType == 'clpt') {
short saveFRef = CurResFile();
SetResLoad(false);
fRefNum = FSpOpenResFile(theSpec, fsRdPerm);
result = ResError();
SetResLoad(true);
if (result == noErr) {
UseResFile(fRefNum);
textHandle = Get1Resource('TEXT', 256);
if (textHandle != nil) {
HLock(textHandle);
ZeroScrap();
textSize = GetHandleSize(textHandle);
result = (OSErr)PutScrap(textSize, 'TEXT', *textHandle);
HUnlock(textHandle);
ReleaseResource(textHandle);
if (result == noErr) {
result = ConvertScrap();
}
} else {
result = resNotFound;
}
CloseResFile(fRefNum);
}
UseResFile(saveFRef);
}
}
return result;
}
/*
*--------------------------------------------------------------
* SoundMyClick
*--------------------------------------------------------------
* Application version of playing a click sound
*--------------------------------------------------------------
*/
void SoundMyClick(void)
{
PlayAClick();
}
/* end of Tabler.App.c */